﻿/*
LICENCE___________________________________________________________________
    Copyright (C) 2012 Reverdy Sylvain

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
FIN LICENCE______________________________________________________________
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;

namespace Merise_designer.Methodes
{
    //Class qui contient les fonctions de type statics
    //Le nom automatique des objets associé à un numéro (id) auto-incrémenté
    public static class CL_Variables
    {
        private const int DEFAULT_VALUE_NUM_AUTO = 111111;
        private static string m_prefixNameAuto = "Nom"; //préfixe du nom auto des objets
        private static int m_idNameAuto = DEFAULT_VALUE_NUM_AUTO; //id auto_incrément des objets
        private static string _nameTitle = "Titre";
        public static string getTitleName() { return _nameTitle; } //nom des titres

        public static string addNameAuto()
        {
           lock(typeof (CL_Variables))
           {
            m_idNameAuto += 1;
            String result = String.Concat(m_prefixNameAuto, getIDNameAuto);
            return result;
           }

        }//Retourne un nouveau nom généré automatiquement
        public static string getPrefixNameAuto//Retourne le préfixe des noms automatiques
        {
            get
            {
                return m_prefixNameAuto;
            }
        }
        public static void setPrefixNameAuto(int value)//Definit le préfixe des noms automatiques
        {
            if (value < DEFAULT_VALUE_NUM_AUTO) value = DEFAULT_VALUE_NUM_AUTO;
            m_idNameAuto = value;
        }
        public static int getIDNameAuto
        {
            get
            {
                return m_idNameAuto;
            }
            set
            {
                m_idNameAuto = value;
            }
        }//Retourne le n° auto actuel (compteur)
        public static void initIDNameAuto() //réinitialise le compteur 
        {
            m_idNameAuto = DEFAULT_VALUE_NUM_AUTO;
        }
    }

    /**
     * Mode MCD ou MLD
     **/

    public static class Mode
    {
        public const int MODE_MCD = 0;
        public const int MODE_MLD = 1;
        
        public const int MODE_SAVE_MANUAL = 0;
        public const int MODE_SAVE_AUTO = 1;

        public static int mode { get; set; }
        public static int mode_save { get; set;}
        
        static Mode(){
            mode = MODE_MCD;
            mode_save = MODE_SAVE_MANUAL;
        }
    }


    /*
     *Informations sur le projet courant (fichier)
     */
    public static class Openroject
    {
        private static String fileBdd;
        private static Boolean cHanged = false;
        public static Boolean isNew { get; set; }
        public static Boolean isSaved { get; set; }

        static Openroject()
        {
            isNew = true;
            isSaved = true;
        }
        
        public static Boolean isCHanged()
        {
            return cHanged;
        }
        public static void SetisCHanged(Boolean value)
        {
            cHanged = value;
        }

        private static void init()
        {
            String fileApp = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Path.DirectorySeparatorChar + Configuration.appFolder + Path.DirectorySeparatorChar;
            if (!Directory.Exists(fileApp)) System.IO.Directory.CreateDirectory(fileApp);

            if (fileBdd == null)
            {
                fileBdd = getInternalBDDFIle();
            }
        }

        public static String getActualProjectFIle()
        {
            init();
            return fileBdd;
        }

        public static void setActualProjectFIle(String fileProject)
        {
            init();
            Openroject.fileBdd = fileProject;
        }

        public static Boolean projectFIleExist()
        {
            init();
            return File.Exists(fileBdd);
        }

        public static String getInternalBDDFIle()
        {
            //return System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "Nouveau.mds";
            return Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Path.DirectorySeparatorChar + Configuration.appFolder+Path.DirectorySeparatorChar+ "Nouveau.mds";
        }
    }
}
